<?php
App::uses('AppController', 'Controller');
/**
 * AdminrosterRosters Controller
 *
 * @property AdminrosterRoster $AdminrosterRoster
 */
class AdminrosterRostersController extends AppController {

/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->AdminrosterRoster->recursive = 0;
		$this->set('adminrosterRosters', $this->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->AdminrosterRoster->exists($id)) {
			throw new NotFoundException('Invalid adminroster roster','default',array('class'=>'alert alert-danger'));
		}
		$options = array('conditions' => array('AdminrosterRoster.' . $this->AdminrosterRoster->primaryKey => $id));
		$this->set('adminrosterRoster', $this->AdminrosterRoster->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->AdminrosterRoster->create();
			if ($this->AdminrosterRoster->save($this->request->data)) {
				$this->Session->setFlash('The new adminroster roster has been saved','default',array('class'=>'alert alert-info'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('The new adminroster roster could not be saved. Please, try again.','default',array('class'=>'alert alert-danger'));
			}
		}
		$adminRosters = $this->AdminrosterRoster->AdminRoster->find('list');
		$rosters = $this->AdminrosterRoster->Roster->find('list');
		$this->set(compact('adminRosters', 'rosters'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->AdminrosterRoster->exists($id)) {
			throw new NotFoundException('Invalid adminroster roster','default',array('class'=>'alert alert-danger'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->AdminrosterRoster->save($this->request->data)) {
				$this->Session->setFlash('The adminroster roster has been successfully edited','default',array('class'=>'alert alert-info'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('The adminroster roster could not be edited. Please, try again.','default',array('class'=>'alert alert-danger'));
			}
		} else {
			$options = array('conditions' => array('AdminrosterRoster.' . $this->AdminrosterRoster->primaryKey => $id));
			$this->request->data = $this->AdminrosterRoster->find('first', $options);
		}
		$adminRosters = $this->AdminrosterRoster->AdminRoster->find('list');
		$rosters = $this->AdminrosterRoster->Roster->find('list');
		$this->set(compact('adminRosters', 'rosters'));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->AdminrosterRoster->id = $id;
		if (!$this->AdminrosterRoster->exists()) {
			throw new NotFoundException('Invalid adminroster roster','default',array('class'=>'alert alert-danger'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->AdminrosterRoster->delete()) {
			$this->Session->setFlash('Adminroster roster deleted','default',array('class'=>'alert alert-info'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash('Adminroster roster was not deleted','default',array('class'=>'alert alert-danger'));
		$this->redirect(array('action' => 'index'));
	}
        
                public function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('index', 'view', 'add', 'edit', 'delete');
        }
        
}
